#coding=utf-8
import time  
from selenium import webdriver  
from selenium.webdriver.common.action_chains import ActionChains


def batch_update(account_id=1153801501135191531, MCC=5331):
        
    driver = webdriver.Chrome(r'C:\Users\guosu\Desktop\chromedriver_win32\chromedriver.exe')

    elem = driver.get('https://admin.paypal.com')
    elem = driver.find_element_by_id("id_accountNo")
    elem.send_keys(account_id)
    elem_search = driver.find_element_by_class_name("findUserSearch").click()
    elem = driver.get('https://admin.paypal.com/cgi-bin/admin?node=supplemental_merchant_info&account_number='+str(account_id))
    driver.execute_script("window.scrollTo(0, (document.body.scrollHeight)/3);")

    js = "document.getElementById('admin_mcc_toggle_status_val').style.display='none';"
    js1 = "document.getElementById('admin_mcc_dynamic_search').style.display='block';"
    js2 = "document.getElementById('admin_mcc').style.display='inline-block';"
    js3 = "document.getElementById('admin_mcc_toggle').style.display='block';"
    js4 = "document.getElementById('admin_mcc_toggle_save').style.display='inline-block';"
    driver.execute_script(js)
    driver.execute_script(js1)
    driver.execute_script(js2)
    driver.execute_script(js3)
    driver.execute_script(js4)
    time.sleep(3)
    driver.find_element_by_id("admin_mcc").send_keys(MCC)
    driver.find_element_by_id("memo_admin_mcc_toggle").send_keys('MCC PROJECT')
    driver.find_element_by_id("admin_mcc_toggle_save").click()
    time.sleep(5)
    driver.quit()


import math
import random
import numpy as np
import os
import xlrd
import pandas as pd


df = pd.read_excel("2.xlsx", sheet_name=0)     # add sheetname in so we can put all data in one excel
account_list = list()
MCC_list = list()
print(df)
i = 0
while (i < len(df)) :
    account_list.append(df.iloc[i][0].tolist())
    MCC_list.append(df.iloc[i][1].tolist())
    i = i + 1
#print(account_list,MCC_list)
    
i = 0
if(len(account_list)==len(MCC_list)):
    for a in account_list:
        #b = "https://admin.paypal.com/cgi-bin/admin?node=supplemental_merchant_info&account_number="+str(a)+"#admin_restrictions_new"
        print("Updating {} time, on account {}".format(str(i+1),a))
        batch_update(account_list[i],MCC_list[i])
        time.sleep(10)
        i += 1
        if i == 20:
            break
else:
    print("Sorry, please check your list and make sure each accounts has an MCC code")


